<template>
  <div class='wy-main matching-tendering wei_tendering'>
    <div class="list_tab">
      <a-form :form="form" @submit="handleSubmit" class="wy-form">
        <a-form-item v-bind="formItemLayout" label="标题">
          <a-input :disabled="disabled"  v-decorator="[ 'messageTitle']" placeholder='请输入标题（50字以内）'   />
        </a-form-item>
        <a-form-item v-bind="formItemLayout" label="发布者">
          <a-input  disabled  v-model="admin1" />
        </a-form-item>
        <a-form-item v-bind="formItemLayout" label="发件人">
          <a-input :disabled="disabled"  v-decorator="[ 'sendUserNickName']" placeholder='请输入公司名称（100字以内）'   />
        </a-form-item>
        <a-form-item v-bind="formItemLayout" label="内容">
          <a-textarea  :disabled="disabled"  :autosize="{ minRows: 4, maxRows: 6 }" v-decorator="[ 'messageContent']"   placeholder='请输入摘要（100字以内）'/>
        </a-form-item>
					<a-form-item label="消息接受人" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }">
						<a-checkbox-group  :disabled="disabled"  style="margin-top: 8px;" v-decorator="[ 'receiveRoles',{initialvalue:rolVal}]">
							<a-checkbox  :disabled="disabled" :value="String(item.id)" v-for="(item,index) in referList" :key="index">
								{{item.name}}
							</a-checkbox>
						</a-checkbox-group>
					</a-form-item>
        <a-form-item v-bind="formItemLayout" label="发布时间">
          <a-input :disabled="disabled"  v-decorator="['createTime']" placeholder='请输入公司名称（100字以内）'   />
        </a-form-item>
        <a-divider class="title-divider" />
      <div class="ant-row ant-form-item" >
        <div class="ant-col-4 ant-form-item-label"></div>
        <div class="ant-col-20 ant-form-item-control-wrapper">
          <div class="ant-form-item-control">
            <div class="ant-title">
              <span class="title-span" style="margin-left:-50px; font-size:16px; font-weight:700; ">审核意见</span>
            </div>
             <div class="ant-radio">
              <a-radio-group v-model="value">
                <!-- v-decorator="['mode']" -->
              <a-radio :value="107">
              通过
              </a-radio>
              <a-radio :value="108">
              拒绝
              </a-radio>
           </a-radio-group>
           </div>
           <div class="a-textarea">
             <a-textarea placeholder="审核意见" v-model="approvalRemarks" style="margin-top: 10px; width: 447px;height:173px;" :rows="4" />
           </div>
          </div>
        </div>
        </div>
          <div class="ant-row ant-form-item" v-if="!datail||type!='add'">
            <div class="ant-col-4 ant-form-item-label"></div>
            <div class="ant-col-10 ant-form-item-control-wrapper">
              <div class="ant-form-item-control">
                <span class="ant-form-item-children">
                  
                  <a-button type="primary"  html-type="submit" style="width: 280px">
                    确认
                  </a-button>
                 <!-- <a-button style="margin-left: 10px;width:100px;" @click="reset">重置</a-button> -->
                  
                </span>
              </div>
            </div>
        </div>
      </a-form>
    </div>
   
  </div>
</template>
<script>
  // import E from 'wangeditor'
  import { environment } from '@/environments/environment'
  import {checkTel, checkTelNum, checkEmail} from 'utils/formValidate'
  import {mapState, mapGetters,mapMutations} from 'vuex'
  //  const editor = new E('#editorElem')

  export default {
    // name: 'editor',
    props: ['type','datail',"isSee"],
    data() {
      return {
        // uploadUrl: environment.FileUploadUrl+'/fileupload/upload',// 图片上传地址
        // FileUploadUrl2:environment.FileUploadUrl2,
        // upload1:'',
        rolVal:[],
        disabled:true,
        // contentCode:1,
        value:107,
        approvalStatus:106,
        // Driver_img:'',
        // coverPic:'',
        // coverPath:'',
        loading: false,
        // vipp:1,
        approvalRemarks:'',
        admin1:'',
        // fileList: [],
        // messageTitle: '',
        // sendUserNickName:'',
        // messageContent:'',
        // createTime:'',
        //消息接收人类型
        referList:[],




        // contentxxx:'',
        formItemLayout: {
          labelCol: {
            xs: {
              span: 24
            },
            sm: {
              span: 4
            },
          },
          wrapperCol: {
            xs: {
              span: 24
            },
            sm: {
              span: 20
            },
          },
        },
      }
    },
    beforeCreate() {
      this.form = this.$form.createForm(this);
    },
    created() {
      this.getRessBook()
        this.admin1 = this.$store.state.account.user.username;
        if(this.datail){

        let d = this.datail
        if(d.approvalStatus==107){
          this.value = 108;
        }else{
          this.value = 107;
        }
        this.approvalRemarks = d.approvalRemarks;
        // console.log(d.receiveRoles.split(','))
        // setTimeout(() => {
        //     this.form.setFieldsValue({
        //     messageTitle:d.messageTitle,
        //     sendUserNickName:d.sendUserNickName,
        //     messageContent:d.messageContent,
        //     createTime:d.createTime,
        //     messageType:d.messageType,
        //     receiveRoles:d.receiveRoles.split(','),
            // receiveRoleList:d.receiveRoleList
        var receiveRoles
        if(d.receiveRoles&&d.receiveRoles.length){
			  receiveRoles = d.receiveRoles.split(',')
        }else{
        	receiveRoles = null
        }
        setTimeout(() => {
            this.form.setFieldsValue({
            messageTitle:d.messageTitle,
            sendUserNickName:d.sendUserNickName,
            messageContent:d.messageContent,
            createTime:d.createTime,
            messageType:d.messageType,
            receiveRoles:receiveRoles,
            // recei
            })
            
            
        }, 100);

        }
    },
    components: {

    },
    watch: {
    },

    mounted: function() {

    },
    computed:{
      ...mapState(['setUser'])
    },
    methods: {
      // 获取消息人列表
			getRessBook() {
				this.$get('/role/open/getRole/system',{
					pageSize : 99,
					pageNum : 1
				},true).then((r) => {
					console.log(r,'12')
					this.referList = r.data.data;
	            }).catch((e) => {})
			},
      // 字典表接口 
      getCommonDict (nameList,type) {
        this.$get('/info/commonDict', {
          dictType: type,
                pageSize: 99,
                pageIndex: 1
        }).then((r) => {
          this[nameList] = r.data.data.rows;
        }).catch((e) => {
        })
      },

      // onChange(e){
      //   this.vipp = e.target.value;
      // },
   
 
      //认证提交
      // handleSubmit(e) {
      //   if(this.datail.approvalStatus == 107){
      //     this.$emit('cancel');
      //     return ;
      //   }
      //   e.preventDefault();
      //   this.form.validateFieldsAndScroll((err, values) => {
      //     values.messageTitle = this.messageTitle
      //     values.sendUserNickName = this.sendUserNickName
      //     values.messageContent = this.messageContent
      //     values.createTime = this.createTime
      //      if(this.datail){
      //       values.messageId = this.datail.messageId
      //     }

      //     if(!err) {
   
      //           // values.approvalStatus = this.approvalStatus
      //           this.$put('message/internalMessage/sent/approval', values,true).then((r) => {
      //           if(r.status == 200){
      //             this.$message.success(r.data.message);
      //             this.form.resetFields();
      //             this.$emit('handleCancel');
      //           }else{
      //             this.$message.error(r.data.message);
      //           }
      //           this.loading = false;
      //         }).catch((e) => {
      //           this.loading = false;
      //         })
      //         }
      //       })
      // },
        handleSubmit(e) {
      if(this.datail.approvalStatus == 107){
          this.$emit('cancel');
          return ;
        }
        e.preventDefault();
        this.form.validateFieldsAndScroll((err, values) => {
            // values.messageTitle = this.messageTitle
            // values.sendUserNickName = this.sendUserNickName
            // values.messageContent = this.messageContent
            // values.createTime = this.createTime
            let val =[]
            val.push({
              messageId:this.datail.messageId,
              approvalRemarks:this.approvalRemarks,
              approvalStatus:this.value,
              // reciveRole:this.reciveRole
            })
            // values.messageId = this.datail.messageId
            // values.approvalRemarks = this.approvalRemarks
            // values.approvalStatus = this.value;
            this.$put('message/internalMessage/sent/approval',val,true).then((r) => {
              if(r.status == 200){
                this.$notification.success({
                  message: r.data.message,
                });
                // this.$message.success('编辑成功!')
              this.form.resetFields();
               this.$emit('cancel');
              }
              this.loading = false;
            }).catch((e) => {
              // console.log(e)
              this.loading = false;
            })
        });
      },





    },
  }
</script>

<style lang="less" scoped>
  .matching-tendering {
    .list_tab {
      margin-top: 10px;
    }
  }


</style>